import java.util.Comparator;
//Class used to define comparisons between fields in the arraylist
public class FieldComparison implements Comparator<Record> {
	String field;
	
	public FieldComparison(String fieldname){
		this.field = fieldname;
	}
	
	public int compare(Record r1,Record r2){

		if(field.equalsIgnoreCase("FN") || field.equalsIgnoreCase("firstname")){
			return (r1.getInfoString("FN").compareTo(r2.getInfoString("FN")));
		}
		else if(field.equalsIgnoreCase("LN") || field.equalsIgnoreCase("lastname")){
			return (r1.getInfoString("LN").compareTo(r2.getInfoString("LN")));
		}
		else if(field.equalsIgnoreCase("POS") || field.equalsIgnoreCase("position")){
			return(r1.getInfoString("POS").compareTo(r2.getInfoString("POS")));
		}
		else if(field.equalsIgnoreCase("X") || field.equalsIgnoreCase("del")){
			return(r1.getInfoString("X").compareTo(r2.getInfoString("X")));
		}
		else if(field.equalsIgnoreCase("ID")){
			return (((Integer)r1.getID()).compareTo((Integer)r2.getID()));
		}
		else{
			throw new UnsupportedOperationException("Not supported");
		}
	}
}
